﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MishraReader.AppServices;
using MishraReader.Entities;
using MishraReader.Services;
using MishraReader.ViewModels.Reader;
using MishraReader.ViewModels.Settings;
using Ninject;
using Ninject.Modules;
using Ninject.Parameters;

namespace MishraReader.ViewModels
{
    public class ViewModelsModule : NinjectModule
    {
        public override void Load()
        {
            Bind<IShareServiceManager>().To<ShareServiceManager>().InSingletonScope();
            Bind<ILightWeakEventManager>().To<LightWeakEventManager>().InSingletonScope();
            Bind<IGoogleReaderService>().To<GoogleReaderService>().InSingletonScope();


            Bind<IShareViewModel>().To<ShareViewModel>();
            Bind<IBookmarkViewModel>().To<BookmarkViewModel>();
            Bind<IItemViewModel>().To<ItemViewModel>();
            Bind<IMishraReaderViewModel>().To<MishraReaderViewModel>();
            
            Bind<IMainViewModel>().To<MainViewModel>();
            Bind<ISignInViewModel>().To<SignInViewModel>();


            Bind<Func<IMishraReaderViewModel>>().ToMethod(
              ctx =>
              () => ctx.Kernel.Get<IMishraReaderViewModel>());

            Bind<Func<ISignInViewModel>>().ToMethod(
                ctx =>
                () => ctx.Kernel.Get<ISignInViewModel>());

            Bind<Func<IShareServicePackage, ServiceAccountViewModel>>().ToMethod(ctx => service =>
                                                                             ctx.Kernel.Get<ServiceAccountViewModel>(new ConstructorArgument("servicePackage",
                                                                                                                                             service)));


            Bind<Func<IShareServicePackage, bool, ShareServiceViewModel>>().ToMethod(
                ctx =>
                (service, isActivated) =>
                {
                    var vm = ctx.Kernel.Get<ShareServiceViewModel>(new ConstructorArgument("servicePackage", service));
                    vm.IsActivated = isActivated;
                    return vm;
                });
        }
    }
}
